home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
zmdm.zoo
/
sz.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-04-27
|
33KB
|
1,712 lines
/*
* ACKNOWLEDGEMENTS
*
* ZMDM was derived from rz/sz for Unix posted by
* Chuck Forsberg (...!tektronix!reed!omen!caf ). We
* thank him for his excellent code, and for giving
* us permission to use and distribute his code and
* documentation.
*
* Atari St version by:
* Jwahar Bammi
* bang: {any internet host}!dsrgsun.ces.CWRU.edu!bammi
* domain: bammi@dsrgsun.ces.CWRU.edu
* GEnie: J.Bammi
*/
#include "config.h"
#define SVERSION "sz 3.03 5-09-89"
#define SSTVERSION "$Revision: 1.77 $ $Date: 1991/04/27 22:12:49 $"
#define OS "Unix V7/BSD"
#ifndef STANDALONE
#define RETURN return
#else
static void RETURN();
void bibi(n) int n; {} /* dummy */
#endif
/* #define SDEBUG */
#include "zmdm.h"
#include "common.h"
#include "zmodem.h"
#ifndef Vsync /* Atari forgot these in osbind.h */
#define Vsync() xbios(37)
#endif
#ifndef Supexec
/* Some versions of osbind don't define Supexec */
#define Supexec(X) xbios(38,X)
#endif
#define SLOGFILE "szlog"
#define purgeline() while(Bconstat(1)) Bconin(1)
#define S_IFDIR 0x0010
/*
* Attention string to be executed by receiver to interrupt streaming data
* when an error is detected. A pause (0336) may be needed before the
* ^C (03) or after it.
*/
#ifdef READCHECK
char Myattn[] = { 0 };
#else
#ifdef USG
char Myattn[] = { 03, 0336, 0 };
#else
char Myattn[] = { 0 };
#endif
#endif
#define TXBMASK (TXBSIZE-1)
static char *txbuf = secbuf; /* Pointer to current file segment */
#if (MWC || MANX || __GNUC__)
FILE *fopen();
#else
FILE *fopen(), *fopenb();
#endif
static long bytcnt, Lastsync;
static unsigned long SaveIntr;
static int Resuming, ForceBin;
static int in;
static int Filesleft;
static long Totalleft;
static long vpos;
static void countem();
#ifndef __GNUC__
extern long stread();
#else
long stread(int, unsigned char *, long);
#endif
/* called by signal interrupt or terminate to clean things up */
#ifndef STANDALONE
void bibis(n)
int n;
{
canit(); flush_modem(); mode(0);
fprintf(STDERR, "\r\nsz: caught signal %d; exiting\n", n);
aexit(128+n);
}
#endif
/* Called when Zmodem gets an interrupt (^X) */
#ifdef ONINTR
void onintr()
{
siggi = 0;
longjmp(intrjmp, -1);
}
#endif
#define ZKER
#ifdef STANDALONE
int main(argc, argv)
#else
int dosz(argc, argv)
#endif
int argc;
char **argv;
{
register char *cp;
register int npats;
int agcnt; char **agcv;
char **patts;
#ifdef STANDALONE
#if (MWC || __GNUC__)
#ifdef MWC
extern char *lmalloc();
#else
#define lmalloc malloc
extern void *lmalloc(unsigned long);
#endif
#endif
/* Set up Dta */
Fsetdta(&statbuf);
/* Get screen rez */
rez = Getrez();
drv_map = Drvmap();
#if (MWC || MANX || __GNUC__)
#ifndef DYNABUF
#if (MWC || __GNUC__)
if((bufr = (unsigned char *)lmalloc((unsigned long)BBUFSIZ))
== (unsigned char *)NULL)
#else
if((bufr = (unsigned char *)Malloc((unsigned long)BBUFSIZ))
== (unsigned char *)NULL)
#endif
#else
if((bufr = dalloc()) == (unsigned char *)NULL)
#endif /* DYNABUF */
{
#ifdef REMOTE
Bauxws("Sorry, could not allocate enough memory\r\n");
#else
Bconws("Sorry, could not allocate enough memory\r\n");
#endif
Pterm(4);
}
#else /* MWC || MANX */
#ifdef DYNABUF
if((bufr = dalloc()) == (unsigned char *)NULL)
{
#ifdef REMOTE
Bauxws("Sorry, could not allocate enough memory\r\n");
#else
Bconws("Sorry, could not allocate enough memory\r\n");
#endif
Pterm(5);
}
#endif /* DYNABUF */
#endif /* MWC || MANX */
#ifndef REMOTE
STDERR = stderr;
#else
#ifndef DLIBS
if((STDERR = fopen("aux:", "rw")) == (FILE *)NULL)
{
Bauxws("Could not Open Aux Stream for Stderr\r\n");
finish();
}
setbuf(STDERR, (char *)NULL);
#else
STDERR = stdaux;
#endif /* DLIBS */
#endif /* REMOTE */
{
int speed;
speed = getbaud();
Baudrate = BAUD_RATE(speed);
SetIoBuf();
Rsconf(speed, 0,-1,-1,-1,-1);
Vsync(); Vsync();
}
#endif /* STANDALONE */
SendType = 1;
Rxtimeout = 600;
npats=0;
Filesleft = 0;
Totalleft = 0L;
txbuf = secbuf;
vpos = 0;
bytcnt = 0;
if (argc<2)
{
susage();
RETURN(1);
}
initz();
#ifndef STANDALONE
schkinvok(argv[0]);
#else
Progname = "sz";
#endif
SaveIntr = Setexc(0x0102, -1L);
BusErr = Setexc(2, -1L);
AddrErr = Setexc(3, -1L);
Verbose = 0;
Resuming = FALSE;
ForceBin = FALSE;
in = (-1);
vdebug = 0;
#ifdef SDEBUG
logf = (FILE *)NULL;
#endif
while (--argc) {
cp = *++argv;
if (*cp++ == '-' && *cp) {
while ( *cp) {
switch(*cp++) {
case '+':
Lzmanag = ZMAPND; break;
#ifdef CSTOPB
case '2':
Twostop = TRUE; break;
#endif
case '7':
Wcsmask=0177; break;
/*
On the St we look up the ext and decide. For Xmodem
transfers, the file is always sent in binary mode
and it is the responsibility of the receiver to
strip CR if so desired.
case 'a':
Lzconv = ZCNL;
Ascii = TRUE; break;
case 'b':
Lzconv = ZCBIN; break;
*/
/* ST extention, force binary, useful to back up every thing
* in image mode, see -B option of rz too +jrb
*/
case 'B':
ForceBin = TRUE;
Lzconv = ZCBIN;
break;
case 'C':
if (--argc < 1) {
susage();
RETURN(1);
}
Cmdtries = atoi(*++argv);
break;
case 'i':
Cmdack1 = ZCACK1;
/* **** FALL THROUGH TO **** */
case 'c':
if (--argc != 1) {
susage();
RETURN(1);
}
Command = TRUE;
Cmdstr = *++argv;
break;
case 'd':
++Dottoslash;
/* **** FALL THROUGH TO **** */
case 'f':
Fullname=TRUE; break;
case 'e':
Zctlesc = 1; break;
case 'k':
Blklen=KSIZE; break;
case 'L':
if (--argc < 1) {
susage();
RETURN(1);
}
blkopt = atoi(*++argv);
if (blkopt<24 || blkopt>1024)
{
susage();
RETURN(1);
}
break;
case 'l':
if (--argc < 1) {
susage();
RETURN(1);
}
Tframlen = atoi(*++argv);
if (Tframlen<32 || Tframlen>1024)
{
susage();
RETURN(1);
}
break;
case 'N':
Lzmanag = ZMNEWL; break;
case 'n':
Lzmanag = ZMNEW; break;
case 'o':
Wantfcs32 = FALSE; break;
case 'p':
Lzmanag = ZMPROT; break;
case 'r':
if (Lzconv == ZCRESUM)
Lzmanag = (Lzmanag & ZMMASK) |
ZMCRC;
Lzconv = ZCRESUM; Resuming = TRUE;
break;
case 'q':
Quiet=TRUE; Verbose=0; break;
case 't':
if (--argc < 1) {
susage();
RETURN(1);
}
Rxtimeout = atoi(*++argv);
if (Rxtimeout<10 || Rxtimeout>1000)
{
susage();
RETURN(1);
}
break;
case 'u':
++Unlinkafter; break;
case 'v':
++Verbose; break;
case 'w':
if (--argc < 1) {
susage();
RETURN(1);
}
Txwindow = atoi(*++argv);
if (Txwindow < 256)
Txwindow = 256;
Txwindow = (Txwindow/64) * 64;
Txwspac = Txwindow/4;
if (blkopt > Txwspac
|| (!blkopt && Txwspac < 1024))
blkopt = Txwspac;
break;
case 'X':
++Modem; break;
case 'Y':
Lskipnocor = TRUE;
/* **** FALLL THROUGH TO **** */
case 'y':
Lzmanag = ZMCLOB; break;
case 'Z':
case 'z':
Lztrans = ZTRLE; break;
default:
susage();
RETURN(1);
}
}
}
else if ( !npats && argc>0) {
if (argv[0][0]) {
npats=argc;
patts=argv;
}
}
}
if (npats < 1 && !Command)
{
susage();
RETURN(1);
}
#ifdef SDEBUG
if (Verbose > 2)
{
if ((logf = fopen(SLOGFILE, "a"))== (FILE *)NULL)
{
fprintf(STDERR, "Can't open log file %s\n",SLOGFILE);
RETURN(0200);
}
fprintf(logf, "Progname=%s\n", Progname);
vdebug = 1;
fflush(logf);
}
#endif
if ( !Quiet)
{
if (Verbose < 2)
Verbose = 2;
}
Setexc(0x0102, bibis);
Setexc(2, buserr);
Setexc(3, addrerr);
if(setjmp(busjmp))
{
/* On a bus error - instead of 2 bombs */
fprintf(STDERR,"\r\nFATAL: Bus Error\n\n");
#ifdef SDEBUG
if(logf != (FILE *)NULL)
fclose(logf);
#endif
if(in != -1)
{
stfclose(in);
in = (-1);
}
canit();
Setexc(2, BusErr);
Setexc(3, AddrErr);
Setexc(0x0102, SaveIntr);
RETURN(2);
}
if(setjmp(addrjmp))
{
/* On address error - instead of 3 bombs */
fprintf(STDERR,"\r\nFA